﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace GameServer.Managers
{
    struct VehicleInfo2
    {
        public int ID, Map, Health, seats;
        int posX, posY, posZ;
        int axisX, axisY, axisZ;

        public VehicleInfo2(int iID, int imap, int iHealth, int iseats, int iposX, int iposY, int iposZ, int iaxisX, int iaxisY, int iaxisZ)
        {
            this.ID = iID;
            this.Map = imap;
            this.Health = iHealth;
            this.seats = iseats;
            this.posX = iposX;
            this.posY = iposY;
            this.posZ = iposZ;
            this.axisX = iaxisX;
            this.axisY = iaxisY;
            this.axisZ = iaxisZ;
        }
    }
    class VehicleManagers2
    {
        private static ArrayList _Vehicles = new ArrayList();

        public static void Load()
        {
            try
            {
                _Vehicles.Clear();

                int[] _VehicleIDs = DB.runReadColumn("SELECT id FROM vehicle", 0, null);
                for (int I = 0; I < _VehicleIDs.Length; I++)
                {
                    string[] EventInfo = DB.runReadRow("SELECT map , maxhealth, seats, positionX, positionY, positionZ,axisX,axisY,axisZ FROM vehicle WHERE id=" + _VehicleIDs[I].ToString());

                    long ExpireDate = long.Parse(EventInfo[2]) + long.Parse(EventInfo[3]);

                    if (Program.currTimeStamp < ExpireDate)
                    {
                        _Vehicles.Add(new VehicleInfo2(_VehicleIDs[I], int.Parse(EventInfo[2]), int.Parse(EventInfo[3]), int.Parse(EventInfo[0]), int.Parse(EventInfo[1]), int.Parse(EventInfo[4]), int.Parse(EventInfo[5]), int.Parse(EventInfo[6]), int.Parse(EventInfo[7]), int.Parse(EventInfo[8])));
                    }
                }

                Log.WriteLine("VehicleManager loaded " + _Vehicles.Count + " vehicles in the memory!");
            }
            catch { }
        }

        public static ArrayList getEvents()
        {
            return _Vehicles;
        }
    }
}
